package org.zn.mvcbase.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**  
*  
* @author 周楠
* @Description: 
*
* @date 2017年8月26日
*
*/
@ConditionalOnProperty(prefix="bootmvc" ,name="errorAdvice",havingValue="true",matchIfMissing=false)
@ControllerAdvice(basePackages="")
public class ExceptionControllerAdvice {
	
	@Autowired(required=false)
	private CommonExceptionResolver exceptionResolver ;
	
	private Logger logger=LoggerFactory.getLogger(ExceptionControllerAdvice.class);
	
	
	@ExceptionHandler(value = Exception.class)
	public ModelAndView  deftalErrorHandler(HttpServletRequest req,HttpServletResponse rep, Exception e){
		
		e.printStackTrace();
		logger.error(e.getMessage());
		
		ModelAndView mv=null;
		
		if(exceptionResolver!=null) {
		
			mv=exceptionResolver.resolveException(req, rep, null, e);
			
		}
		
		return mv;
		
	}
	
	
	

}
